home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / edit1.cq / edit1.c
Encoding:
C/C++ Source or Header  |  1985-06-03  |  17.3 KB  |  673 lines

  1. /*        EDIT.C  - Screen Editor
  2.         by Bill Kinnersley
  3.         MSU Physics Dept
  4.         January 1982
  5. EDIT has many of the conveniences of WordStar, but is a much smaller and
  6. faster program.  The program is presently limited to editing files of less
  7. than 44K total length, and lines shorter than 80 characters. */
  8.  
  9. #define ESC        0x1b        /* escape */
  10. #define BELL        0x07
  11. #define DC1        0x11        /* dc1 = x-on */
  12. #define DC3        0x13        /* dc3 = x-off */
  13. #define EOFCHAR        0x1a        /* end-of-file marker */
  14.  
  15. #include stdio.h
  16.  
  17. char *topmem;            /* pointer to top of memory */
  18. char *topfile;            /* pointer to top of file */
  19. char *botfile;            /* pointer to bottom of file */
  20. char *topscr;            /* pointer to top of screen */
  21. char *botscr;            /* pointer to bottom of screen */
  22. char *cursor;            /* pointer to current cursor position in file */
  23. char *null;            /* null pointer*/
  24. char *mark;            /* temporary pointer */
  25. int lines;            /* line # where botscr is (1 <= lines <=25) */
  26. int csr_col;            /* current cursor column # */
  27. int want_col;            /* cursor column desired */
  28. int csr_line;            /* current cursor line # */
  29. int next_char;            /* next input char, input during screen output*/
  30. int ch;                /* current character input from keyboard */
  31. int flag;            /* true if cursor==topscr */
  32. int itop;            /* topfile as an integer */
  33. int ibot;            /* botfile as an integer */
  34. int mar_left;            /* left margin */
  35. int mar_right;            /* right margin */
  36. char bufin[80];
  37. char fid[28];            /* name of file to edit */
  38. char backup[28];        /* name of backup file */
  39. int file;            /* file descriptor # used by C */
  40. int new;            /* true if file was new */
  41. int i;                /* number of records written to disk */
  42. main(argc,argv)
  43. int argc;            /* number of arguments in command line */
  44. int *argv[];            /* pointers to those arguments */
  45. {
  46.     topmem = CCAVAIL() - 4096;    /* get size of available memory */
  47.     cursor = CCALLOC(topmem);
  48.     *cursor++ = '\n';        /* dummy new/line */
  49.     botfile = topfile = botscr = topscr = cursor;
  50.     topmem = botfile + topmem;    /* point to top of available memory */
  51.     null = "";
  52.     next_char = 0;
  53.     mar_left = 0; mar_right = 79;    /* set margins */
  54.     term_init();
  55.     if (argc == 1)        /* no command tail */
  56.     {    fputs("\nFILE? : ",stderr);    /* ask for fid */
  57.         gets(fid);
  58.     }
  59.     else strcpy(fid,argv[1]);    /* fid from command line */
  60.     fid[26] = 0;            /* trim to 26 chars */
  61.     new = - swapin(fid,topfile);        /* try to read in */
  62.     clear_screen();
  63.     csr_line = csr_col = want_col = 0;
  64.     if (new)
  65.     {    fputs("NEW FILE\n\n",stderr);    /* must be new file*/
  66.         lines = 3;
  67.         *botfile = EOFCHAR;
  68.         csr_line = 2;
  69.     }
  70.     else
  71.     {    while (*botfile != EOFCHAR) botfile++;    /* look for botfile*/
  72.         lines = 1;
  73.         setbot();
  74.         putscr(topfile);
  75.         home();
  76.     }
  77.  
  78.     while(TRUE)
  79.     {    ch = get_conin();    /* wait for console input */
  80.         if (ch == ESC ) ch = escape();    /* convert escape sequence */
  81.         if (((ch >= ' ') && (ch < 127)) || (ch == '\t') || (ch == '\r'))
  82.             ins_character();
  83.         else if (special())    /* process special characters */
  84.             return;        /* quit */
  85.     }
  86. }
  87. ins_character()
  88. /* insert character c at current cursor position */
  89. {    disable_keyboard();
  90.     e_eol();
  91.     ibot = ++botfile; itop = ++cursor;
  92.     ++botscr;
  93.     movmem(cursor-1,cursor,ibot-itop+1);
  94.     if (ch == '\r') ch = '\n';    /* convert CR to NEW/LINE */
  95.     *(cursor-1) = ch;
  96.     if (ch == '\n')
  97.         {where();
  98.         csr_col = want_col = 0;
  99.         if (csr_line == 23)
  100.             {botscr = cursor;
  101.             lines = 25;
  102.             printbot();
  103.             }
  104.         else
  105.             {putch('\n');
  106.             setbot();
  107.             ins_line();
  108.             putline(cursor);
  109.             csr_line++;
  110.             put_cursor(csr_line,csr_col);
  111.             }
  112.         }
  113.     else
  114.         {putch(ch);
  115.         if (ch != '\t') csr_col++;
  116.         else csr_col = ((csr_col>>3)+1)<<3;
  117.         want_col = csr_col;
  118.         putline(cursor);
  119.         position();
  120.         }
  121.     enable_keyboard();
  122. }
  123. special()
  124. /* procedure to process special characters */
  125. {        switch (ch) {
  126. /* cursor right */    case 'D'-64 :if (cursor == botfile) break;
  127.                 else if ((ch=*cursor++)=='\n')
  128.                     {printbot(); csr_col=0;}
  129.                 else if (ch=='\t')
  130.                     {putch('\t');
  131.                     csr_col = ((csr_col>>3)+1)<<3;}
  132.                 else {cup_right(); csr_col++;}
  133.                 want_col = csr_col;
  134.                 break;
  135. /* cursor left */    case 'S'-64 :
  136.             case 'H'-64 : flag = (cursor==topscr);
  137.                 if (cursor==topfile) break;
  138.                 else if ((ch=*--cursor)=='\n')
  139.                     {reverse_index();
  140.                     if (flag)
  141.                         {topscr=startline(cursor);
  142.                         setbot();
  143.                         putch('\r');
  144.                         putline(topscr);}
  145.                     position();
  146.                     }
  147.                 else if (ch=='\t') position();
  148.                 else {putch('\b'); csr_col--;}
  149.                 want_col = csr_col;
  150.                  break;
  151. /* cursor up */        case 'E'-64 :
  152.                 if ((mark=startline(cursor))==topfile) break;
  153.                 cursor = startline(mark-1);
  154.                 disable_keyboard();
  155.                 reverse_index();
  156.                 where();
  157.                 if (mark==topscr) {topscr = cursor;
  158.                         setbot();
  159.                         cup_home();
  160.                         putline(topscr);}
  161.                 set_cursor();
  162.                 enable_keyboard();
  163.                 break;
  164. /* cursor down */    case 'X'-64 :
  165.             case 'J'-64 : if ((mark = next(cursor))==null) break;
  166.                 cursor = mark;
  167.                 printbot();
  168.                 where();
  169.                 set_cursor();
  170.                 break;
  171. /* up screenful */    case 'R'-64 : if (topscr==topfile) break;
  172.                 disable_keyboard();
  173.                 where();
  174.                 botscr = topscr;
  175.                 settop();
  176.                 newscr();
  177.                 enable_keyboard();
  178.                 break;
  179. /* down screenful */    case 'C'-64 : if (botscr==botfile) break;
  180.                 disable_keyboard();
  181.                 topscr = botscr;
  182.                 setbot();
  183.                 newscr();
  184.                 enable_keyboard();
  185.                 break;
  186. /* top file */        case 'T'-64 : if (topscr==topfile) break;
  187.                 topscr = topfile;
  188.                 setbot();
  189.                 newscr();
  190.                 break;
  191. /* bottom file */    case 'B'-64 : if (botscr==botfile) break;
  192.                 botscr = botfile;
  193.                 settop();
  194.                 lines = 24;
  195.                 newscr();
  196.                 cursor=botscr;
  197.                 csr_line=23; csr_col=0;
  198.                 put_cursor(csr_line,csr_col);
  199.                 break;
  200. /* scroll down */    case 'Z'-64 : if (botscr==botfile) break;
  201.                 where();
  202.                 put_cursor(23,0);
  203.                 bdos(6,'\n');
  204.                 botscr=next(botscr);
  205.                 settop();
  206.                 putline(startline(botscr-1));
  207.                 if (cursor < topscr) cursor=next(cursor);
  208.                 if (csr_line > 0) csr_line--;
  209.                 set_cursor();
  210.                 break;
  211. /* scroll up */        case 'W'-64 : if (topscr==topfile) break;
  212.                 cup_down();    /* move cursor down */
  213.                 where();    /* save current cursor position */
  214.                 cup_home();
  215.                 reverse_index();
  216.                 topscr=startline(topscr-1);
  217.                 setbot();
  218.                 putline(topscr);
  219.                 if (cursor >= botscr) cursor=startline(botscr-1);
  220.                 set_cursor();
  221.                 break;
  222. /* find */        case 'F'-64 : clear_screen(); con_flush();
  223.                 fputs("FIND? :",stderr);
  224.                 gets(bufin);
  225.                 cursor = topfile;
  226. /* refind */        case 'L'-64 : for (mark=cursor; mark!=botfile; mark++)
  227.                     if (*mark == bufin[0])
  228.                         if (comp())
  229.                             {topscr=startline(mark);
  230.                             setbot();
  231.                             newscr();
  232.                             cursor=mark;
  233.                             position();
  234.                             break;}
  235.                 if (mark==botfile) {
  236.                     putch(BELL);
  237.                     /* goto top; */
  238.                     if (cursor == topfile) {
  239.                         topscr=startline(cursor);
  240.                         setbot();
  241.                         newscr();
  242.                         position();
  243.                     }
  244.                 }
  245.                 break;
  246. /* keep */        case 'K'-64 : clear_screen(); con_flush();
  247.                 fputs("Saving ",stderr);
  248.                 fputs(fid,stderr);
  249.                 fputs(".\n",stderr);
  250.                 if (!new) {strcpy(backup,fid);
  251.                     for (ch=0; ch<15; ch++)
  252.                         if (backup[ch] == '.' || backup[ch] == ' ')
  253.                             backup[ch]=0;
  254.                     strcat(backup,".BACKUP");
  255.                     unlink(backup); rename(fid,backup);
  256.                     }
  257.                 if ((file=creat(fid))==NULL) {
  258.                     fputs("Can't open ",stderr);
  259.                     fputs(fid,stderr);
  260.                     fputs(".\n",stderr);
  261.                     return;
  262.                 }
  263.                 ibot = botfile;    /* change pointers */
  264.                 itop = topfile;    /* to integers  */
  265.                 i = (ibot-itop)/128+1;
  266.                 if (write(file,topfile,i)!=i)
  267.                      fputs("WRITE ERROR\nDisk full?",stderr);
  268.                 term_reset();
  269.                 exit(0);
  270. /* quit */        case 'Q'-64 : clear_screen(); con_flush();
  271.                 fputs("QUIT? ",stderr);
  272.                 if((ch=getchar())=='Y'||ch=='y'||ch=='Y'-64)
  273.                     {fputs("\nEdit Abandoned\n",stderr);
  274.                     term_reset(); return TRUE;}
  275.                 clear_screen();
  276.                 putscr(cursor=topscr);
  277.                 home();
  278.                 break;
  279. /* delete character */    case 'G'-64 : if (cursor == botfile) break;
  280.                 disable_keyboard();
  281.                 ibot = --botfile; itop = cursor;
  282.                 --botscr;
  283.                 ch = *cursor;
  284.                 movmem(cursor+1,cursor,ibot-itop);
  285.                 if (ch == '\n')
  286.                     {position();
  287.                      where();
  288.                      setbot();
  289.                      putline(cursor);
  290.                      putch('\n');
  291.                      delete_line();
  292.                      put_cursor(csr_line,csr_col);
  293.                     }
  294.                 else {putline(cursor);
  295.                     position();}
  296.                 enable_keyboard();
  297.                 break;
  298. /* delete */        case 0x7f : if (cursor == topfile) break;
  299.                 disable_keyboard();
  300.                 flag = (cursor == topscr);
  301.                 ibot = --botfile; itop = --cursor;
  302.                 --botscr;
  303.                 ch = *cursor;
  304.                 movmem(cursor+1,cursor,ibot-itop+1);
  305.                 if (flag)
  306.                     {putline(topscr=startline(cursor));
  307.                     position();
  308.                     }
  309.                 else if (ch == '\n')
  310.                     {cup_up();
  311.                      position();
  312.                      where();
  313.                      setbot();
  314.                      putline(cursor);
  315.                      putch('\n');
  316.                      delete_line();
  317.                      put_cursor(csr_line,csr_col);
  318.                     }
  319.                 else {if (ch == '\t') position();
  320.                         else putch('\b');
  321.                     putline(cursor);
  322.                     position();}
  323.                 enable_keyboard();
  324.                 break;
  325.             default: putch(BELL);    /* invalid character */
  326.     }
  327.     return FALSE;
  328. }
  329. comp()
  330. {int i;
  331.     for (i=0; bufin[i]!=0; i++) if (bufin[i] != mark[i]) return FALSE;
  332.     mark = mark + i;
  333.     return TRUE;
  334. }
  335. newscr()
  336. /* puts a new screen */
  337. {    clear_screen();
  338.     putscr(cursor=topscr);
  339.     home();
  340. }
  341. startline(start)
  342. char *start;
  343. /* returns pointer to first character in current line */
  344. {char *mark;
  345.     for(mark=start-1; mark!=topfile; mark--)
  346.         if (*mark=='\n') return ++mark;
  347.     return topfile;
  348. }
  349. next(start)
  350. char *start;
  351. /* returns pointer to first character in next line */
  352. {char *mark;
  353.     for(mark=start; mark!=botfile; mark++)
  354.         if (*mark=='\n') return ++mark;
  355.     return null;
  356. }
  357. position()
  358. /* positions screen cursor in the current line */
  359. {char *mark,i;
  360.     csr_col=0;
  361.     for (mark=startline(cursor); mark!=cursor; mark++)
  362.         if (*mark=='\t')
  363.             csr_col=((csr_col>>3)+1)<<3;/* count up column position*/
  364.             else csr_col++;
  365.     put_cursor(26,csr_col);    /* dummy for H19 */
  366.     want_col = csr_col;
  367. }
  368. set_cursor()
  369. /* positions file cursor to position screen cursor on desired column */
  370. {int tab_col;
  371.     csr_col=0;
  372.     for (cursor=startline(cursor); *cursor!='\n'; cursor++) {
  373.         if (cursor == botfile) break;
  374.         if (csr_col == want_col) break;
  375.         if (*cursor != '\t') csr_col++;
  376.         else {
  377.             tab_col=((csr_col>>3)+1)<<3;
  378.             if (want_col < tab_col) break;
  379.             csr_col = tab_col;
  380.         }
  381.     }
  382.     put_cursor(csr_line,csr_col);
  383. }
  384. putline(start)
  385. char *start;
  386. /* outputs from "start" to end of current line;
  387.    returns pointer to first char in next line */
  388. {char *mark; int i;
  389.     e_eol();
  390.     for (mark=start; mark!=botfile; mark++)
  391.         if (*mark=='\n') return mark+1;
  392.         else putch(*mark);
  393.     return botfile;
  394. }
  395. printbot()
  396. /* prints a line at the bottom of screen and scrolls up */
  397. {    putch('\n');
  398.     if (cursor == botscr)
  399.         {if (lines==25) while (*topscr++ != '\n');
  400.         if (botscr == botfile);
  401.         botscr = putline(cursor);
  402.         putch('\r');
  403.         }
  404. }
  405. setbot()
  406. /* measures down 24 lines from topscr to set botscr */
  407. {    lines=0;
  408.     for (botscr=topscr; botscr!=null; botscr=next(botscr))
  409.          if (++lines==25) return;
  410.     botscr=botfile;
  411. }
  412. putscr(start)
  413. char *start;
  414. /* outputs from "start" to botscr */
  415. {char *mark;
  416.     if (start==botscr) return;
  417.     e_eol();
  418.     for (mark=start; mark!=(botscr-1); mark++) {
  419.         if (*mark == '\n') {
  420.             e_eol();        /* erase to end of line */
  421.             bdos(6,'\r');        /* output carriage return */
  422.             if (mark != (botscr-1)) bdos(6,'\n');
  423.         }
  424.         else putch(*mark);
  425.         if (!next_char) {
  426.             next_char = bdos(6,-1);    /* look-ahead for dc3 */
  427.             if (next_char == DC3) {
  428.                 while (!(next_char=bdos(6,-1)));
  429.                 if (next_char == DC1) next_char = 0;
  430.             }
  431.         }
  432.     }
  433.     if (lines<25) putch(*mark);
  434.     e_eos();
  435. }
  436. home()
  437. {    cup_home();
  438.     csr_line = csr_col = want_col = 0;
  439. }
  440. settop()
  441. /* measures up 23 or 24 lines from "botscr" */
  442. {int i,j;
  443.     i = j = (botscr == botfile);
  444.     for (topscr=botscr; topscr!=topfile; topscr=startline(topscr-1))
  445.             if (++i==25) break;
  446.     lines = i - j;
  447.     setbot();
  448. }
  449. reverse_index()
  450. /* move cursor up one line, scrolling screen down if at top */
  451. {    putch(ESC); putch('M');
  452. }
  453. ins_line()
  454. /* insert new blank line on screen at current position */
  455. {    putch(ESC); putch('['); putch('L');
  456. }
  457. delete_line()
  458. /* delete the current line, scroll bottom of screen, output bottom line */
  459. {    putch(ESC); putch('['); putch('M');
  460.     if (lines<25) return;
  461.     putch(ESC); putch('['); putch('2'); putch('4'); putch(';');
  462.     putch('1'); putch('H');
  463.     putline(startline(botscr-1));
  464. }
  465. putch(c)
  466. int c;
  467. /* replacement for library putc (will not swallow characters) */
  468. {    if (c == '\n') bdos(6,'\r');
  469.     bdos(6,c);
  470. }
  471. get_conin()
  472. {int c;
  473.     c = next_char;
  474.     if (c) next_char = 0;
  475.     else while (!(c=bdos(6,-1)));;
  476.     return c;
  477. }
  478. con_flush()
  479. {    while(bdos(6,-1));        /* flush type-ahead */
  480. }
  481. escape()
  482. /* procedure to process escape sequences */
  483. {int c;
  484.     c = get_conin();    /* get next character */
  485.     if (c == '[') {
  486.         c = get_conin();    /* get next character */
  487.         switch(c) {
  488. /* cursor up */        case 'A' : c = 'E'-64; break;
  489. /* cursor down */    case 'B' : c = 'X'-64; break;
  490. /* cursor forward */    case 'C' : c = 'D'-64; break;
  491. /* cursor backword */    case 'D' : c = 'S'-64; break;
  492. /* home */        case 'H' : c = 'T'-64; break;
  493. /* delete character */    case 'P' : c = 'G'-64; break;
  494.             default : c = 0; putch(BELL);
  495.         }
  496.     }
  497.     else if (c == 'O') {    /* keypad or function key */
  498.         c = get_conin();    /* get next character */
  499.         switch(c) {
  500. /* blue */        case 'P' : c = 'K'-64; break;
  501. /* red */        case 'Q' : c = 'Q'-64; break;
  502. /* f1 */        case 'S' : c = 'F'-64; break;
  503. /* f2 */        case 'T' : c = 'L'-64; break;
  504.  
  505. /* shift down */    case 'r' : c = 'C'-64; break;
  506. /* shift home */    case 'u' : c = 'B'-64; break;
  507. /* shift up */        case 'x' : c = 'R'-64; break;
  508.             default : c = 0; putch(BELL);
  509.         }
  510.     }
  511.     else {c = 0; putch(BELL);}
  512.     return c;    /* return modified character */
  513. }
  514. where()
  515. {    int c;
  516.     putch(ESC); putch('['); putch('6'); putch('n');/* get cursor position */
  517.     while (get_conin() != ESC);
  518.     while (get_conin() != '[');
  519.     csr_line = csr_col = 0;
  520.     while ((c = get_conin()) != ';') csr_line = csr_line * 10 + c - '0';
  521.     while ((c = get_conin()) != 'R') csr_col = csr_col * 10 + c - '0';
  522.     --csr_line; --csr_col;        /* adjust cursor to 0-origin */
  523. }
  524. put_cursor(line,col)
  525. int line;
  526. int col;
  527. {    bdos(6,ESC); bdos(6,'[');
  528.     ++line; ++col;
  529.     if (line > 9) bdos(6,line/10 + '0');
  530.     bdos(6,line%10 + '0');
  531.     bdos(6,';');
  532.     if (col > 9) bdos(6,col/10 + '0');
  533.     bdos(6,col%10 + '0');
  534.     bdos(6,'H');
  535. }
  536. clear_screen()
  537. {    cup_home();
  538.     bdos(6,ESC); bdos(6,'['); bdos(6,'J');
  539. }
  540. e_eol()
  541. {    bdos(6,ESC); bdos(6,'['); bdos(6,'K');
  542. }
  543. e_eos()
  544. {    bdos(6,ESC); bdos(6,'['); bdos(6,'J');
  545. }
  546. cup_home()
  547. {    bdos(6,ESC); bdos(6,'['); bdos(6,'H');
  548. }
  549. cup_up()
  550. {    bdos(6,ESC); bdos(6,'['); bdos(6,'A');
  551. }
  552. cup_down()
  553. {    bdos(6,ESC); bdos(6,'['); bdos(6,'B');
  554. }
  555. cup_right()
  556. {    bdos(6,ESC); bdos(6,'['); bdos(6,'C');
  557. }
  558. disable_keyboard()
  559. {    bdos(6,ESC); bdos(6,'['); bdos(6,'2'); bdos(6,'h');
  560. }
  561. enable_keyboard()
  562. {    bdos(6,ESC); bdos(6,'['); bdos(6,'2'); bdos(6,'l');
  563. }
  564. term_init() {
  565.     bdos(6,ESC); bdos(6,'['); bdos(6,'>');
  566.     bdos(6,'6');            /* Enter keypad shifted mode */
  567.     bdos(6,';');
  568.     bdos(6,'7');            /* Enter alternate keypad mode */
  569.     bdos(6,'h');
  570. }
  571. term_reset()
  572. {    bdos(6,ESC); bdos(6,'['); bdos(6,'>');
  573.     bdos(6,'6');            /* Exit keypad shifted mode */
  574.     bdos(6,';');
  575.     bdos(6,'7');            /* Exit alternate keypad mode */
  576.     bdos(6,'h');
  577. }
  578. bdos (bc, de) int bc, de; {
  579. #asm
  580.     MOVE.L    8(SP),D0    get bc (function)
  581.     CMPI.B    #6,D0
  582.     BEQ.S    *+4
  583.     RTS
  584.     MOVE.L    4(SP),D2    get de
  585.     BMI.S    CON_IN    console input
  586.     MOVEQ    #8,D1
  587.     SC    SC:DEVOUT
  588.     RTS
  589. CON_IN    DS    0
  590.     MOVEQ    #8,D1
  591.     SC    SC:DEVSTS
  592.     BNE.S    CON_IN1
  593.     MOVEQ    #0,D0
  594.     RTS
  595. CON_IN1    DS    0
  596.     MOVEQ    #8,D1
  597.     SC    SC:DEVIN
  598.     MOVE.L    #$FF,D0
  599.     AND.L    D1,D0
  600. ;    RTS        supplied by CC
  601. #endasm
  602. }
  603. strcpy( d, s) char *d, *s; {
  604.     while (*s) *d++ = *s++;
  605.     *d = 0;
  606. }
  607. strcat( d, s) char *d, *s; {
  608.     while (*d) ++d;            /* locate end of destination string */
  609.     while (*s) *d++ = *s++;        /* copy source to destination */
  610.     *d = 0;
  611. }
  612. movmem(s, d, l) char *s, *d; int l; {
  613. #asm
  614.     MOVE.L    4(SP),D0    get length
  615.     BGT.S    *+4        don't move if zero
  616.     RTS
  617.     CMPI.L    #$1FFFF,D0
  618.     BLT.S    *+6
  619.     TRAP    15
  620.     DC    0    breakpoint trap
  621.     MOVE.L    12(SP),A0    get source address
  622.     MOVE.L    8(SP),A1    get destination address
  623.     CMPA.L    A1,A0    compare source with destination
  624.     BLT.S    MOVE_0    move top to bottom
  625.     SUBQ.L    #1,D0    adjust for DBRA counter
  626.     MOVE.B    (A0)+,(A1)+
  627.     DBRA    D0,*-2
  628.     ADDQ.W    #1,D0
  629.     SUBQ.L    #1,D0
  630.     BGT    *-8
  631.     RTS
  632. MOVE_0    DS    0
  633.     ADD.L    D0,A0
  634.     ADD.L    D0,A1
  635.     SUBQ.L    #1,D0    adjust for DBRA counter
  636.     MOVE.B    -(A0),-(A1)
  637.     DBRA    D0,*-2
  638.     ADDQ.W    #1,D0
  639.     SUBQ.L    #1,D0
  640.     BGT    *-8
  641. ;    RTS            ; return supplied by CC
  642. #endasm
  643. }
  644. gets(s) char *s; {
  645.     return (fgets(s, 20, stderr));
  646. }
  647. swapin( fname, addr) char *fname, *addr; {
  648.     int i;
  649.     if ((file=fopen(fname,"r"))==NULL) return 1;
  650.     while (1) {
  651.         if ((fgets(addr,topmem-addr,file))==0) break;
  652.         while (*addr) ++addr;
  653.         *addr++ = '\n';
  654.     }
  655.     *addr = EOFCHAR;
  656.     fclose(file);
  657.     return 0;
  658. }
  659. rename(from, to) char *from, *to; {
  660.     if (CCRENAME(from, to) == ERR) fputs("Error on rename\n",stderr);
  661. }
  662. creat(fname) char *fname; {
  663.     return fopen(fname,"w");
  664. }
  665. write(file,buf,sects) int file, sects; char *buf; {
  666.     *botfile = 0;
  667.     fputs(buf,file);
  668.     return sects;
  669. }
  670. P),A1    get destination address
  671.     CMPA.L    A1,A0    compare source with destination
  672.     BLT.S    MOVE_0    move top to bottom
  673.     SUBQ.L    #1,D0